import table from '@/components/dt/table/render.js'
import Opt from '@/components/dt/info/Opt.js'

let _this = null

class leaveCaseColumns extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        title: '序号',
        type: 'index',
        width: 70,
        align: 'center'
      },
      {
        field: 'userName',
        minWidth: 180,
        header: {
          filter: {
            title: '姓名',
            key: 'userNameOrWorkNo',
            placeholder: '请输入姓名',
            input: {}
          }
        },
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.targetCaseName
                ? params.row.userName +
                  '<span style=color:red>(待' +
                  params.row.targetCaseName +
                  '接收)</span>'
                : params.row.userName,
              isHtml: true,
              tipsTxt: params.row.targetCaseName
                ? params.row.userName + '(待' + params.row.targetCaseName + '接收)'
                : params.row.userName
            })
          }
        }
      },
      {
        title: '工号 ',
        field: 'workNo',
        minWidth: 120
      },
      {
        title: '手机号',
        field: 'phone',
        minWidth: 150
      },
      {
        title: '角色',
        field: 'roleNames',
        minWidth: 180,
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.roleNames
                ? params.row.roleNames.length > 0
                  ? params.row.roleNames.join(',')
                  : '-'
                : '-'
            })
          }
        }
      },
      {
        title: '所属组别',
        field: 'groupName',
        minWidth: 100,
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.groupName ? params.row.groupName : '无'
            })
          }
        }
      },
      {
        title: '状态',
        field: 'buildingType',
        minWidth: 100,
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.buildingType
                ? params.row.buildingType == 3
                  ? '离案'
                  : params.row.buildingType == 4
                  ? '离职'
                  : '-'
                : '-'
            })
          }
        }
      },
      {
        title: '分摊比例（%）',
        field: 'amortizationRatio',
        minWidth: 140
      },
      {
        title: '是否组长',
        field: 'groupLeader',
        minWidth: 100,
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.groupLeader ? (params.row.groupLeader == 1 ? '是' : '否') : '否'
            })
          }
        }
      },
      {
        title: '是否在编',
        field: 'compile',
        minWidth: 100,
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.compile ? (params.row.compile == 1 ? '是' : '否') : '-'
            })
          }
        }
      },
      {
        title: '离场日期',
        field: 'exitDate',
        minWidth: 120,
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.exitDate ? _this.$tool.formatterDate(params.row.exitDate) : '-'
            })
          }
        }
      },
      {
        title: '操作',
        field: 'operation',
        width: 180,
        align: 'center',
        fixed: 'right',
        slots: {
          default: (params, h) => {
            let btns = []
            if (!params.row.targetCaseName) {
              btns.push({
                title: '查看',
                event: 'checkUser',
                data: params.row
              })
              btns.push({
                title: _this.unlocking('0102030400') ? '变更' : '',
                event: 'changeUser',
                data: params.row
              })
            }
            return table.cell.btns(_this, h, btns)
          }
        }
      }
    ]
  }
}

export default leaveCaseColumns
